<?php
namespace App\Models;

class Test extends \CodeIgniter\Model{
	protected $db;
	public function __construct(){
		parent::__construct();
		$this->db= \Config\Database::connect();
	}
	public function get1($id){
		return $this->db->table('article')->where('id', $id)->get()->getRow();
	}
	public function list($page=1, $max=10){
		$count=$this->db->table('article')->countAll();
		$list=[];
		if($count>0) $list=$this->db->table('article')->limit($max, ($page-1)*$max)->get()->getResultArray();
		return [$count, $list];
	}
	public function add($data){
		$result=$this->db->table('article')->insert($data);
		return $result?$this->db->insertID():false;
	}
	public function edit($id, $data){
		return $this->db->table('article')->where(['id'=>$id])->update($data);
	}
	public function del($id){
		return $this->db->table('article')->where(['id'=>$id])->delete();
	}
}
